#ifndef CAN_MOTOR_H
#define CAN_MOTOR_H
#define GM6020_VOLTMODE //gm6020电压模式 
#include "struct_typedef.h"

#define DOWN_GIMBAL_CAN hcan2
#define UP_GIMBAL_CAN hcan1
#define DOWN_SHOOT_CAN hcan2
#define UP_SHOOT_CAN hcan1
#define TOCHASSIS_CAN hcan1
//云台和底盘使用的是不同的中心板，连接了不同的can端口。
//解决冲突和吞吐率问题，接线时需要注意。
//当我们使用同一个端口时，可以修改为
// #define GIMBAL_CAN hcan1

//电机的类型和约定的id枚举类型。通过修改这里的值对应更改电机
#ifdef GM6020_CURRNETMODE
typedef enum
{

    CAN_UP_G_CAN1_ID = 0x2FE,  //上云台6020
    CAN_PITCH_UP = 0x20A,

    CAN_UP_M_CAN1_ID = 0x200,  //上云台 3508
    CAN_SHOOT_UP_L = 0x202,
    CAN_SHOOT_UP_R = 0x203,

    CAN_UP_OTHER_CAN1_ID=0x200,   //上云台2006
    CAN_SHOOT_UP_TRIGGER = 0x204,

    CAN_DOWN_G_CAN2_ID = 0x2FE, //下云台6020
    CAN_YAW_UP = 0x209,
    CAN_PITCH_DOWN = 0x20A,

    CAN_DOWN_G_CAN1_ID = 0x2FE,
    CAN_YAW_DOWN = 0x209, //通过can1发送

    CAN_DOWN_M_CAN2_ID = 0x1FF,  //下云台3508
    CAN_SHOOT_DOWN_L = 0x205,
    CAN_SHOOT_DOWN_R = 0x206,
   
    CAN_DOWN_OTHER_CAN1_ID=0x1FF,  //下云台2006
    CAN_SHOOT_DOWN_F_TRIGGER=0x207, //通过can1发送
    CAN_SHOOT_DOWN_S_TRIGGER=0x208, //通过can1发送

} can_msg_id_e;
#endif

#ifdef GM6020_VOLTMODE
typedef enum
{

    CAN_UP_G_CAN1_ID = 0x2FF,  //上云台6020
    CAN_PITCH_UP = 0x20A,

    CAN_UP_M_CAN1_ID = 0x200,  //上云台 3508
    CAN_SHOOT_UP_L = 0x202,
    CAN_SHOOT_UP_R = 0x203,

    CAN_UP_OTHER_CAN1_ID=0x200,   //上云台2006
    CAN_SHOOT_UP_TRIGGER = 0x204,

    CAN_DOWN_G_CAN2_ID = 0x2FF, //下云台6020
    CAN_YAW_UP = 0x209,
    CAN_PITCH_DOWN = 0x20A,

    CAN_DOWN_G_CAN1_ID = 0x2FF,
    CAN_YAW_DOWN = 0x209, //通过can1发送

    CAN_DOWN_M_CAN2_ID = 0x1FF,  //下云台3508
    CAN_SHOOT_DOWN_L = 0x205,
    CAN_SHOOT_DOWN_R = 0x206,
   
    CAN_DOWN_OTHER_CAN1_ID=0x1FF,  //下云台2006
    CAN_SHOOT_DOWN_F_TRIGGER=0x207, //通过can1发送
    CAN_SHOOT_DOWN_S_TRIGGER=0x208, //通过can1发送

} can_msg_id_e;
#endif

//电机的虚拟ID枚举,根据情况注释[节约内存]
typedef enum
{
  // CHASSIS_LF_M,         //M3508
  // CHASSIS_RF_M,
  // CHASSIS_RB_M,
  // CHASSIS_LB_M,
  // CHASSIS_LF_G,          //GM6020
  // CHASSIS_RF_G,
  // CHASSIS_RB_G,
  // CHASSIS_LB_G,
  // YAW_DOWN,
  //下面的顺序不能改变 
    PITCH_UP, 
    SHOOT_UP_L,
    SHOOT_UP_R,
    SHOOT_UP_TRIGGER,           
    YAW_UP,                 
    PITCH_DOWN,
    YAW_DOWN,
    SHOOT_DOWN_L,            
    SHOOT_DOWN_R,
    SHOOT_DOWN_F_TRIGGER,
    SHOOT_DOWN_S_TRIGGER,                
    //下面可以继续加
    LENGTH_OF_MOTOR_ID,
    
} motor_virtual_ID;


// 电机数据结构体。
typedef struct
{
    uint16_t ecd;
    int16_t speed_rpm;
    int16_t given_current;
    uint8_t temperate;
    int16_t last_ecd;
} motor_measure_t;

typedef struct
{
    int8_t x;		//[-127,127]线性映射
    int8_t y;		//
    int8_t w;		//
    int8_t nextmode; //下一个模式
}toDownSTM_t; //fromGimbalSTM_t

void CAN_cmd_GM_and_downSTM(int16_t yawDown,int16_t pitchUp);
void CAN_cmd_downtrigger(int16_t shootdownFtrigger, int16_t shootdownStrigger);
void CAN_cmd_downgimbal(int16_t yawup, int16_t pitchdown);
void CAN_cmd_downshoot(int16_t shootdownL, int16_t shootdownR);
void CAN_cmd_upshoot(int16_t shootupL, int16_t shootupR,int16_t shootuptrigger);

// 用于给外面的函数提供数据

/**
  * @brief          返回云台电机 3508电机数据指针
  * @param[in]      i: 电机编号,范围[0,10]
  * @retval         电机数据指针
  */
extern const motor_measure_t *get_gimbal_motor_measure_point(uint8_t i);

extern toDownSTM_t * get_to_down_stm_point(void);
#endif


/*示例
        CAN_cmd_chassis(4000, 4000, 4000, 4000);
        HAL_Delay(2);
        CAN_cmd_gimbal(10000, 10000, 10000, 10000);
        HAL_Delay(2);
*/
